home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
090
/
pctj8508.arc
/
KWIC.PLI
< prev
next >
Wrap
Text File
|
1986-09-14
|
3KB
|
118 lines
kwic:proc options(main);
/* KWIC (Keyword in Context) system. */
/* create or augment list of noise words, ie words which
are ignored for indexing, setting them up in an ordered
tree structure, eliminating duplicates */
dcl (infile,outfile) char(14) var;
dcl (incount, outcount,i,j,k) bin fixed;
dcl in file,
out file;
dcl inrec char(20) varying;
dcl (inline,outrec) char (250) varying;
%include 'wordstr';
PUT list ('KWIC (Keyword-in-context) system');
Put skip list ('build or augment list of noise words.');
PUT skip list ('First read list of predefined noise words.');
PUT skip list ('Enter name of input file ');
GET edit(infile)(A);
PUT skip list ('Enter name of output file ');
GET edit(outfile)(A);
put skip(2);
open file(in) stream input title(infile);
open file(out) stream output title(outfile) print;
on endfile (in) begin;
put skip(3) list('number of records input = ',incount);
go to exit;
end;
/* general initialization */
start=null;
p=addr(start);
ioloop:
do incount = 0 by 1;
get file(in) list (inrec);
put list (inrec);
call find;
end ioloop;
exit:
close file(in);
put skip list ('enter file to be scanned for more words ');
get list (infile);
open file(in) title(infile) stream input;
on endfile (in) begin;
put skip(3) list('number of records processed = ',incount);
go to exit2;
end;
ioloop2:
do incount = 0 by 1;
read file(in) into (inline);
/* remove all special characters and convert to upper case */
outrec=translate(inline,
'
ABCDEFGHIJKLMNOPQRSTUVWXYZ
ABCDEFGHIJKLMNOPQRSTUVWXYZ ');
PUT skip list(inline);
/* pick out each word */
j=1;
do while(j<length(inline));
do j = j to length(inline) while(substr(outrec,j,1)=' ');
end;
do k = j to length(inline) while(substr(outrec,k,1)^=' ');
end;
if j<length(inline)
then do;
inrec=substr(outrec,j,k-j);
call find;
end;
j=k+1;
end;
end ioloop2;
signal endfile(in);
exit2:
/* logical end-of-program */
call traverse(start);
/* logical end of program */
find:proc;
/* find word in binary tree */
p = start;
p2=addr(start);
do while(p^=null&word^=inrec);
if word<inrec
then do;
p2=addr(higher);
p=higher;
end;
else do;
p2=addr(lower);
p=lower;
end;
end;
if p=null
then do;
allocate wordlist set(p);
link=p;
lower=null;
higher=null;
word=inrec;
end;
end find;
traverse:proc(pstart) recursive;
dcl pstart ptr;
%include 'wordstr';
p = pstart;
if lower^=null
then call traverse(lower);
put list(word);
put file(out) list(word);
if higher^=null
then call traverse(higher);
end traverse;
end kwic;